package com.ff.xyh.front.listener;

import com.ff.xyh.common.entity.post.PostImg;
import com.ff.xyh.feign.client.minio.MinioClient;
import com.ff.xyh.feign.client.post.PostImgClient;
import com.ff.xyh.front.config.PostRabbitConfig;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;

import java.time.LocalTime;

/**
 * @Auther FF
 * @Date 2023年 01月 03日
 * @Time 01:08
 */

@Component
public class FileRabbitListener {

    @Autowired
    private MinioClient minioClient;


    /**
     * 消费uploadFile队列
     * @param file
     * @param path
     */
    @RabbitListener(queues = PostRabbitConfig.Queue_UploadFile)
    public void uploadFileQueueConsumer1(MultipartFile file, String path) {
        minioClient.uploadFileToPath(file, path);
    }


    /**
     * 消费uploadFile死信队列
     * @param file
     * @param path
     */
    @RabbitListener(queues = PostRabbitConfig.Dead_Queue_PostImg)
    public void postImgDeadQueueConsumer(MultipartFile file, String path) {
        System.out.println("文件:" + file.getOriginalFilename() +"上传失败，再次重试，若失败则丢弃");
        minioClient.uploadFileToPath(file, path);
    }

}
